# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import tools
from odoo import api, fields, models


class fhtest_Report(models.Model):
    _name = "fhtest.report"
    _description = "fhtest"
    _auto = False
    _rec_name = 'fname'
    _order = 'id desc'

    fname= fields.Many2one('hr.employee',u'商品',readonly=False,required=False,translate=False)
    origin = fields.Char(string='Source Document', help="Reference of the document that generated this sales order request.")  
    FAddperson =fields.Many2one('hr.employee',u'添加人',readonly=False,required=False,translate=False,default=lambda self: self.get_employee())
    FConsultant=fields.Many2one('hr.employee',u'班主任',readonly=False,required=False,translate=False)					   
    FAdddate= fields.Datetime(u'添加日期',readonly=False,required=False,translate=False, default=fields.Datetime.now)
    state=fields.Selection([('draft',u'草稿'),('wait_prove',u'提交申请'),('proved',u'主管审批')], u'状态', required=False, default='draft')				   
    FDisable=fields.Selection([('0',u'启用'),('1',u'停用')],u'是否停用',readonly=False,required=False,translate=False) 

    def _select(self):
        select_str = """           
             SELECT l.id as id,
                    l.fname as fname,
                    l.origin as origin,
                    l.FAddperson as FAddperson,
                    l.FConsultant as FConsultant,					
                    l.FAdddate as FAdddate,					
                    l.state as state,					
                    l.FDisable as FDisable		
        """ 
        return select_str

    def _from(self):
        from_str = """
                fhtest_weishui001  l
        """
        return from_str

    def _group_by(self):
        group_by_str = """
            GROUP BY l.fname
        """
        return group_by_str

    @api.model_cr
    def init(self):
        tools.drop_view_if_exists(self.env.cr, self._table)
        self.env.cr.execute("""CREATE or REPLACE VIEW %s as (
                    SELECT l."id" as "id",
                    l."fname" as "fname",
                    l."origin" as "origin",
                    l."FAddperson" as "FAddperson",
                    l."FConsultant" as "FConsultant",					
                    l."FAdddate" as "FAdddate",					
                    l."state" as "state",					
                    l."FDisable" as "FDisable"  FROM fhtest_weishui001  l  GROUP BY l."id"					
            )""" % (self._table))
